package com.linearList;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * @Author: linKe
 * @Date: 2021/12/31 22:50
 * @FileName: SinglyListCycleTest
 * @version: 1.0
 * @Description: 单向循环链表测试类
 */
public class SinglyListCycleTest {

    SinglyListCycle<Integer> list;

    @Before
    public void setUp() throws Exception {
        Integer [] arr = {1,3,5,7,9};
        list = new SinglyListCycle<Integer>(arr);
    }

    @Test
    public void isEmpty() {
        boolean empty = list.isEmpty();
        System.out.println(empty);
        // false 正常
    }

    @Test
    public void get() {
        for (int i = 1; i < 6; i++) {
            System.out.println(list.get(i));
        }
        /*
        *   1
            3
            5
            7
            null    get（5）的时候没有值 p.next != this.head最后一句 返回的时候判断为false
          修改判断条件后
            1
            3
            5
            7
            9
            * */
    }

    @Test
    public void set() {
        list.set(2,222);
        System.out.println(list.get(2));
        //  222
    }

    @Test
    public void size() {
        int size = list.size();
        System.out.println(size);
        // 5
    }

    @Test
    public void insert() {
        Node<Integer> insert = list.insert(2, 3333);
        System.out.println(insert.data);
        System.out.println(list.get(2));
        System.out.println(list.get(3));
        System.out.println(list.get(4));
        /*
        * 3333
          null  这个null 值不对
          修改get 返回判断后
            3333
            3
            3333
            5
            */
    }

    @Test
    public void remove() {
        Integer remove = list.remove(2);
        System.out.println(remove);
        //
        Integer integer = list.get(2);
        System.out.println(integer);
        System.out.println(list.get(3));
        /*
        5   这个数据为什么是5 起始循环的顺序不对
            这里是从1开始遍历的,等同于 序号3 而我的下标是从1开始计算的
        3
        结点是正常删除了的
        3
        7
        * */
    }

    @Test
    public void search() {
        Node<Integer> search = list.search(9);
        Integer data = search.data;
        System.out.println(data);
        //9
    }

    @Test
    public void testEquals() {
        Integer [] arr1 = {1,3};
        SinglyListCycle<Integer> list1 = new SinglyListCycle<>(arr1);
        boolean equals1 = list1.equals(list);
        System.out.println(equals1);
        // true 这个判断也不对
        //
        // 修改判断条件后  false
        Integer [] arr2 = {1,3,5,7,9};
        SinglyListCycle<Integer> list2 = new SinglyListCycle<>(arr2);
        boolean equals2 = list2.equals(list);
        System.out.println(equals2);
        //
        //  true 头结点的数据域的值同为null的比较
    }
}